home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 10 / FM Towns Free Software Collection 10.iso / ms_dos / tool / fapxtool / src / txl / txllcx.c < prev    next >
C/C++ Source or Header  |  1995-02-12  |  3KB  |  135 lines

  1. /***************
  2. *
  3. * g:\exe\txl\src\txllcx.c
  4. */
  5. #include "txl.h"
  6.  
  7. /**************** in line LCX module ************************/
  8.  
  9. char *get_filename(char *wildcard)
  10. {
  11.     static struct find_t filedata;
  12.     static char wc[76] = "";
  13.     static char fullpath[80];
  14.     char *npos;
  15.     int ret;
  16.  
  17.     if (strcmp(wc, wildcard) != 0) {
  18.         strcpy(wc, wildcard);
  19.         ret = _dos_findfirst(wc, _A_ARCH | _A_NORMAL | _A_RDONLY, &filedata);
  20.     }
  21.     else {
  22.         ret = _dos_findnext(&filedata);
  23.     }
  24.  
  25.     if (ret == 0) {
  26.         strcpy(fullpath, wildcard);
  27.         if ((npos = jstrrchr(fullpath, '\\')) != NULL) {
  28.             strcpy(npos + 1, filedata.name);
  29.         }
  30.         else if ((npos = jstrchr(fullpath, ':')) != NULL) {
  31.             strcpy(npos + 1, filedata.name);
  32.         }
  33.         else {
  34.             strcpy(fullpath, filedata.name);
  35.         }
  36.         if (strstr(fullpath, ".BAK") != NULL) {
  37.             return (get_filename(wildcard));
  38.         }
  39.         return (fullpath);
  40.     }
  41.     else {
  42.         return (NULL);
  43.     }
  44. }
  45.  
  46. void lcx (char *lcxinputfile)
  47. {
  48.     int chr = NUL,type = CT_ANK;
  49.     long int size = 0, clum = 0, ret = 0, retx = 0;
  50.     FILE *input;
  51.  
  52.     if (lcxinputfile != NULL) {
  53.         input = fopen(lcxinputfile, "rb");
  54.     }
  55.     else {
  56.         errexit("Cannot open inputfile.");
  57.     }
  58.     if (input == NULL) {
  59.         fprintf(stderr, "Error:cannot open input file\n");
  60.         Exit(1);
  61.     }
  62.  
  63.     while(chr != EOF) {
  64.         chr = getc(input);
  65.         type = chkctype(chr, type);
  66.         size++;
  67.         clum++;
  68.         if (chr == 0x0a) {
  69.             ret++;
  70.             retx++;
  71.             clum = 0;
  72.         }
  73.         if (((clum == 80) && (type == CT_KJ1)) || (clum > 80)) {
  74.             clum = 0;
  75.             retx++;
  76.         }
  77.     }
  78. /*
  79.     if (input == stdin) {
  80.         size += ret;
  81.     }
  82. */
  83.     size--;
  84.  
  85.     fprintf(fpmes, "%10ld%10ld%10ld ", ret, size, retx);
  86.     if (*lcxinputfile != NUL) {
  87.         fprintf(fpmes, "%s", lcxinputfile);
  88.     }
  89.  
  90.     totalret += ret;
  91.     totalretx += retx;
  92.     totalsize += size;
  93.     putc(RET, fpmes);
  94.  
  95.     fclose(input);
  96.  
  97. }
  98.  
  99. void lcxdriver(char *param[])
  100. {
  101.     int fileno = 0,i;
  102.     char *filename;
  103.     char *fence = "----------+---------+---------+------------------------\n";
  104.  
  105.     fprintf(stderr, "TXL inline module LCX Ver1.20\n");
  106.     fprintf(fpmes,  "     Lines     Bytes ViewLines Filename\n");
  107.     fprintf(fpmes, fence);
  108.  
  109.     if (param[0][0] == NUL) {
  110.         fileno++;
  111.         lcx(NULL);
  112.     }
  113.     else {
  114.         for (i = 0; param[i] != NULL; i++) {
  115.             do {
  116.                 filename = get_filename(param[i]);
  117.                 if (filename != NULL) {
  118.                     lcx(filename);
  119.                     fileno++;
  120.                 }
  121.             } while(filename != NULL);
  122.         }
  123.     }
  124.     if (fileno > 1) {
  125.         fprintf(fpmes, fence);
  126.         fprintf(fpmes, "%10ld%10ld%10ld TOTAL\n",
  127.             totalret, totalsize, totalretx);
  128.     }
  129.     Exit(0);
  130.  
  131. }
  132.  
  133. /***************end of LCX*********************/
  134.  
  135.